import axios from 'axios'
import { Message } from 'element-ui'
import NProgress from 'nprogress'



// 隐藏掉，右上角的加载 
NProgress.configure({ showSpinner: false });

const TIMEOUT = 10000
const service = axios.create({
  baseURL: process.env.VUE_APP_BASE_API,
  timeout: TIMEOUT,
  withCredentials: true,// 跨域请求时 需要使用凭证
  headers: {
    // timestamp: +new Date(),// 加上时间戳
  },
  params: {
    timestamp: +new Date(),// 加上时间戳
  }
})
service.interceptors.request.use(config => {
  NProgress.start()
  return config;
}, err => {

});

service.interceptors.response.use(res => {
  NProgress.done()
  return res.data;

}, err => {
  // console.dir(err);
  NProgress.done()
  // Message({
  //   type: 'error',
  //   message: err.response.data.message
  // })
  return Promise.reject(err.response.data)
})
export default service